package com.yh.homestay.controller;


import com.yh.homestay.common.HomeStayResult;
import com.yh.homestay.common.StaffEditResult;
import com.yh.homestay.pojo.UserStaff;
import com.yh.homestay.service.UserStaffService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.List;

@Controller
public class UserStaffController {
    @Autowired
    private UserStaffService userStaffService;

    /**
     * @param
     * @return
     */
    @RequestMapping(value = "/staff-list" ,produces = "application/json; charset=utf-8")
    @ResponseBody
    public HomeStayResult selectAll(String staffName, Integer page, Integer limit){
        HomeStayResult homeStayResult = userStaffService.selectAll(staffName ,page ,limit);
        return homeStayResult;
    }
    /**
     * @param userStaff
     * @return
     */
    @RequestMapping("/staff-add")
    public HomeStayResult addstaff(UserStaff userStaff){
        int staff = userStaffService.addStaff(userStaff);
        if(staff>0){
            return HomeStayResult.ok();
        }else{
            return HomeStayResult.build(500,"系统正忙,请稍后添加!");
        }
    }

    /**
     *
     * @param
     * @return
     */
    @RequestMapping("/staff-edit/{id}")
    @ResponseBody
    public HomeStayResult editStaff(@PathVariable Integer id, String staffName, String staffPhone, Date staffHiredate, Double staffSalary, Double staffComm, Integer staffMgr){
        HomeStayResult update = userStaffService.update(id,staffName,staffPhone,staffHiredate,staffSalary,staffComm,staffMgr);
        return update;
    }

    /**
     * @param id
     * @return
     */
    @RequestMapping("/staff-delete/{id}")
    @ResponseBody
    public HomeStayResult deleteById(@PathVariable Integer id){
        HomeStayResult delete = userStaffService.delete(id);
        return delete;
    }

    @RequestMapping("/staff-edit/selectOne/{id}")
    @ResponseBody
    public StaffEditResult editstaff(@PathVariable Integer id){
        StaffEditResult staffEditResult = userStaffService.selectOne(id);
        return staffEditResult;
    }
  @RequestMapping("/staff-deleteAll")
  @ResponseBody
  public HomeStayResult delectAll(@RequestParam List<Integer> ids){
      HomeStayResult actionResult = userStaffService.delectAll(ids);
      return actionResult;
  }
 }
